/*
 * @Date: 2024-04-02 16:05:22
 * @LastEditors: bingkui.wu
 * @LastEditTime: 2024-04-02 16:06:16
 * @Description: 获取教材和年级信息
 */
import { REQUEST } from "#type/request";
import Response from "@common/Response";
import { BookGrade } from "@models/BookGrade";
import { BookCategory } from "@models/BookCategory";

const root: REQUEST.BASIC = {
    auth: false,
    method: "get",
    request: async (ctx: any) => {
        const categories = await BookCategory.find().lean().select('-_id categoryId categoryName').exec();
        const grades = await BookGrade.find().lean().select('-_id gradeId gradeName categoryId').exec();
        return Response.Success(categories.map(category => {
            return {
                ...category,
                grades: grades.filter(m => m.categoryId === category.categoryId)
            }
        }));
    },
};

export default root;
